#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    struct dirent **namelist;
    int n;

    n = scandir(".", &namelist, NULL, versionsort);
    if (n == -1) {
        perror("scandir");
        exit(EXIT_FAILURE);
    }

    // while (n--) {
    //     printf("%s\n", namelist[n]->d_name);
    //     free(namelist[n]);
    // }
    for (int i = 0; i < n; i++) {
        printf("%s\n", namelist[i]->d_name);
        free(namelist[i]);
    }
    free(namelist);

    exit(EXIT_SUCCESS);
}
